import React, { useEffect } from 'react';
import './Login.scss'
import { LockOutlined, UserOutlined } from '@ant-design/icons';
import { Button, notification, Form, Input, message } from 'antd';
import { user_list } from '../../api/index'
import { useNavigate } from 'react-router-dom';
interface props {

}
function Login(props: props) {
  //查询数据
  useEffect(() => {

  }, [])
  // 实例化路由对象
  var navigate = useNavigate();
  const onFinish = (values: any) => {
    console.log('Received values of form: ', values);
    user_list(values).then((res) => {
      console.log(res.data);
      if (res.data.length == 1) {
        notification.open({
          message: '提醒',
          description:
            '登录成功',
          duration: 1,
          onClick: () => {
            console.log('Notification Clicked!');
          },
        });
        localStorage.setItem('token', res.data[0].token)
        localStorage.setItem('user', res.data[0].username)
        navigate('/index')
      }
    })
  };
  // 去注册
  var goRestegr = () => {
    navigate('/Restegr')
  }
  return (
    <div className='small'>
      <div className='small-header'>
        政府服务管理页面
      </div>
      <div className='form'>
        <span className='aa'>登录页面</span>

        <Form
          name="normal_login"
          className="login-form"
          initialValues={{ remember: true }}
          onFinish={onFinish}
        >
          <Form.Item
            name="username"
            rules={[{ required: true, message: '请输入你的账号' }]}
          >
            <Input prefix={<UserOutlined className="site-form-item-icon" />} placeholder="输入用户名" />
          </Form.Item>
          <Form.Item
            name="password"
            rules={[{ required: true, message: '请输入你的密码' }]}
          >
            <Input
              prefix={<LockOutlined className="site-form-item-icon" />}
              type="password"
              placeholder="输入密码"
            />
          </Form.Item>
          <Form.Item>
            <Button type="primary" htmlType="submit" className="login-form-button">
              登录
            </Button>
          </Form.Item>
        </Form>
        <span className='djl' onClick={goRestegr}>去注册</span>
      </div>

    </div>
  );
}

export default Login;